using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarOFDDiscountDB
    {
        public CarOFDDiscountDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarOFDDiscount carofddiscount)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarOFDDiscountInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarOFDDiscountId", carofddiscount.ProviderCarOFDDiscountId);
            _sPara.Add("@ProviderCompanyId", carofddiscount.ProviderCompanyId);
            _sPara.Add("@OFDPercent", carofddiscount.OFDPercent);
            _sPara.Add("@DiscountPercent", carofddiscount.DiscountPercent);
            _sPara.Add("@RefCEUserId", carofddiscount.RefCEUserId);
            _sPara.Add("@Status", carofddiscount.Status);
            //_sPara.Add("@Info1", template.Info1);
            //_sPara.Add("@Info2", template.Info2);
            //_sPara.Add("@Info3", template.Info3);
            //_sPara.Add("@Info4", template.Info4);
            //_sPara.Add("@Info5", template.Info5);
            //_sPara.Add("@NInfo1", template.NInfo1);
            //_sPara.Add("@NInfo2", template.NInfo2);
            //_sPara.Add("@FInfo1", template.FInfo1);
            //_sPara.Add("@FInfo2", template.FInfo2);
            //_sPara.Add("@DInfo1", template.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CarOFDDiscount GetProviderCarOFDDiscount(Int64 ProviderCompanyId, Int32 OFDPercent)
        {
            CarOFDDiscount _ofddiscount = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarOFDDiscountSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@OFDPercent", OFDPercent);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _ofddiscount = new CarOFDDiscount();
                    _ofddiscount = FillDataRecord(_dt, 0);
                }
            }
            return _ofddiscount;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        private CarOFDDiscount FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarOFDDiscount myCarOFDDiscount = new CarOFDDiscount();
            myCarOFDDiscount.ProviderCarOFDDiscountId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarOFDDiscountId"].ToString());
            myCarOFDDiscount.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarOFDDiscount.OFDPercent = Convert.ToInt32(myDataTable.Rows[RowId]["OFDPercent"].ToString());
            myCarOFDDiscount.DiscountPercent = Convert.ToInt32(myDataTable.Rows[RowId]["DiscountPercent"].ToString());
            myCarOFDDiscount.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarOFDDiscount.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            myCarOFDDiscount.CreatedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["CreatedDate"].ToString());
            myCarOFDDiscount.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());
            return myCarOFDDiscount;
        }

    }
}